package com.user.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

@Data
@Configuration
@ConfigurationProperties(prefix = "redis")
public class JedisConfig {
    private String host;
    private int port;
    private int timeout;
    private String password;
    private int poolMaxToal;
    private int poolMaxIdle;
    private int poolMaxWait;

    @Bean
    public JedisPool jedisPool(){
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(poolMaxToal);
        config.setMaxIdle(poolMaxIdle);
        config.setMaxWaitMillis(poolMaxWait);
        JedisPool jedisPool = new JedisPool(config,host,port,timeout);
        return jedisPool;
    }
}
